package com.szgz.platform.model;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.time.LocalDateTime;

@Data
@TableName("user")
public class User {
    
    @TableId(value = "user_id", type = IdType.ASSIGN_UUID)
    private String userId;
    
    @TableField("username")
    private String username;
    
    @TableField("email")
    private String email;
    
    @TableField("password_hash")
    @JsonIgnore
    private String password;
    
    @TableField("role")
    private String role;
    
    @TableField("status")
    private String status;
    
    @TableField("created_at")
    private LocalDateTime createdAt;
    
    @TableField("updated_at")
    private LocalDateTime updatedAt;
    
    @TableField("last_login")
    private LocalDateTime lastLogin;
    
    // ===== 高校学生相关信息 =====
    @TableField("real_name")
    private String realName;

    @TableField("student_no")
    private String studentNo;

    @TableField("school_name")
    private String schoolName;

    @TableField("college_name")
    private String collegeName;

    @TableField("major_name")
    private String majorName;

    @TableField("class_name")
    private String className;

    @TableField("grade")
    private String grade;

    @TableField("enrollment_year")
    private Integer enrollmentYear;

    @TableField("graduation_year")
    private Integer graduationYear;

    @TableField("gender")
    private String gender;

    @TableField("phone")
    private String phone;

    @TableField("avatar_url")
    private String avatarUrl;

    @TableLogic
    @TableField("deleted")
    private Boolean deleted;
    
    // 构造函数
    public User() {
        this.deleted = false;
        this.createdAt = LocalDateTime.now();
        this.updatedAt = LocalDateTime.now();
    }
    
    // 构造函数
    public User(String username, String email, String password) {
        this();
        this.username = username;
        this.email = email;
        this.password = password;
        this.role = "USER";
        this.status = "ACTIVE";
    }
    
    // 构造函数
    public User(String username, String email, String password, String role) {
        this(username, email, password);
        this.role = role;
    }
    
    // 更新用户信息
    public void updateUser(String username, String email) {
        this.username = username;
        this.email = email;
        this.updatedAt = LocalDateTime.now();
    }
    
    // 设置密码
    public void setPassword(String password) {
        this.password = password;
        this.updatedAt = LocalDateTime.now();
    }
    
    // 更新状态
    public void updateStatus(String status) {
        this.status = status;
        this.updatedAt = LocalDateTime.now();
    }
    
    // 记录登录时间
    public void recordLogin() {
        this.lastLogin = LocalDateTime.now();
        this.updatedAt = LocalDateTime.now();
    }
    
    // 检查是否是管理员
    public boolean isAdmin() {
        return "ADMIN".equals(this.role);
    }
    
    // 检查用户是否激活
    public boolean isActive() {
        return "ACTIVE".equals(this.status);
    }
    
    // 检查用户是否被删除
    public boolean isDeleted() {
        return Boolean.TRUE.equals(this.deleted);
    }
} 